Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct flags for log file #13

Merged
merged 1 commit into from
Feb 17, 2024
Merged

Conversation

seiyab
Copy link
Contributor

@seiyab seiyab commented Feb 17, 2024

Trying grype, I found that it overwrites previous content in log file without truncating. So in some situations, log file can be broken. Feel free to ask me to use other flags like O_APPEND or O_EXCL.

Reproduction:

printf 'previous content\n%.0s' {1..10} > my-log.txt
GRYPE_LOG_LEVEL=info GRYPE_LOG_FILE=./my-log.txt go run ./cmd/grype alpine

Resulting my-log.txt:

[0000]  INFO grype version: [not provided]
[0001]  INFO found 12 vulnerability matches across 15 packages
ious content
previous content
previous content
previous content

Merging this, resulting my-log.txt wil be:

[0000]  INFO grype version: [not provided]
[0001]  INFO found 12 vulnerability matches across 15 packages

Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me @seiyab; thanks! Since we're already overwriting any existing file here, truncating it seems like the right thing to do if it exists.

@kzantow kzantow merged commit ee28a48 into anchore:main Feb 17, 2024
3 checks passed
@seiyab seiyab deleted the correct-log-file-flags branch February 18, 2024 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants